package handler

import (
	"context"
	authpb "coolcar/proto/auth_out/v1"
	"coolcar/srvs/auth_srv/dao"
	"fmt"

	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"

	"go.uber.org/zap"
)

type Service struct {
	Logger *zap.Logger
	Mongo  *dao.Mongo
	authpb.UnimplementedAuthServiceServer
}

func (s Service) Login(c context.Context, request *authpb.LoginRequest) (*authpb.LoginResponse, error) {
	fmt.Println("Login", request.Account, request.Password)
	accountID, err := s.Mongo.ResolveAccountID(request.Account, request.Password)
	if err != nil {
		s.Logger.Error("can not resolve account id", zap.Error(err))
		return nil, status.Error(codes.Internal, "内部错误")
	}

	fmt.Println("accountID", accountID)
	return &authpb.LoginResponse{
		UserId: accountID,
	}, nil
}
